import Store from "@/store";
import ServerInfo from "@/static/json/serverInfo.json";
export default class AbstractService {
  protected GetData(url: string, data: any = null) {
    return this.buildReqest("GET", url, data);
  }
  protected PostData(url: string, data: any = null) {
    return this.buildReqest("POST", url, data);
  }
  protected PutData(url: string, data: any = null) {
    return this.buildReqest("PUT", url, data);
  }
  protected DeleteData(url: string, data: any = null) {
    return this.buildReqest("DELETE", url, data);
  }
  private buildReqest(method: "GET" | "POST" | "PUT" | "DELETE", url: string, data: any) {
    return new Promise(resolve => {
      uni.request({
        url: ServerInfo.baseUrl + url,
        method: method,
        data: data,
        header: Store.Common.requestHeader,
        success: res => {
          resolve(res);
        },
        fail(err) {
          resolve(err);
        },
      });
    });
  }
}
